------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure3.log
  log type:  text
 opened on:  14 Jan 2019, 15:42:44

. #delimit ;
delimiter now ;
. *     ***************************************************************** *;
. *     ***************************************************************** *;
. *       File-Name:      figure3.do                                      *;
. *       Date:           January 14, 2019                                *;
. *       Author:         MRG/CC                                          *;
. *       Purpose:        Produce Figure 3 for It's Not Only What You     *;
. *                       Say, It's Also How You Say It: The Strategic    *;
. *                       Use Of Campaign Sentiment. Journal of Politics. *;
. *                       Forthcoming.                                    *;
. *           Input File:     sentiment.dta                                   *;
. *       Output File:    figure3.log                                     *;
. *       Data Output:    none                                            *;
.              *       Previous file:  sentiment.dta                                   *;
. *       Machine:        desktop/laptop                                                  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *        Load data                                                      *;
. *     ****************************************************************  *;
. use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

. *     ****************************************************************  *;
. *       Declare data to be panel, where the panel is based on language  *;
. *     ****************************************************************  *;
. xtset language;
       panel variable:  language (unbalanced)

. xtsum positive_sentiment;

Variable         |      Mean   Std. Dev.       Min        Max |    Observations
-----------------+--------------------------------------------+----------------
positi~t overall |  1.696912   1.446166       -.68        7.6 |     N =     421
         between |              1.34797   .4018627     4.3828 |     n =       7
         within  |             .7198334  -1.565888   4.914112 | T-bar = 60.1429

. *     ****************************************************************  *;
. *       Generate additional variables that we will need for our         *;
. *       analysis.                                                       *;
. *     ****************************************************************  *;
. gen incumbent_inflation_l = incumbent*inflation_l;
(21 missing values generated)

. label var incumbent_inflation "incumbent*inflation_l";

. gen incumbent_unemployment_l = incumbent*unemployment_l;
(7 missing values generated)

. label var incumbent_unemployment_l "incumbent*unemployment_l";

. gen incumbent_pm = incumbent*pm;

. label var incumbent_pm "incumbent*pm";

. gen incumbent_fm = incumbent*fm;

. label var incumbent_fm "incumbent*fm";

. gen left_right2=left_right*left_right;
(39 missing values generated)

. label var left_right2 "left_right*left_right";

. gen extremist = 0;

. replace extremist=1 if family_id ==14 | family_id==40;
(87 real changes made)

. replace extremist = . if family_id==.;
(9 real changes made, 9 to missing)

. label var extremist "1 if communist/socialist or far right, 0 otherwise";

. gen extremist2 = 0;

. replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
(124 real changes made)

. replace extremist2 = . if family_id==.;
(9 real changes made, 9 to missing)

. label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";

. gen extremist_inflation_l=extremist*inflation_l;
(30 missing values generated)

. label var extremist_inflation "extremist*inflation_l";

. gen extremist_unemployment_l=extremist*unemployment_l;
(16 missing values generated)

. label var extremist_unemployment_l "extremist*unemployment_l";

. tabulate language, gen(l);

   language |      Freq.     Percent        Cum.
------------+-----------------------------------
      Dutch |        102       24.23       24.23
    English |         85       20.19       44.42
     French |         36        8.55       52.97
     German |         46       10.93       63.90
    Italian |         54       12.83       76.72
 Portuguese |         50       11.88       88.60
    Spanish |         48       11.40      100.00
------------+-----------------------------------
      Total |        421      100.00

. *     ****************************************************************  *;
. *      Change graph scheme                                                  *;
. *     ****************************************************************  *;
. ssc install scheme-burd, replace;
checking scheme-burd consistency and verifying not already installed...
all files already exist and are up to date.

. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *       Produce Figure 3                                                *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. matrix crab = J(3,2,.);

. matrix coln crab = estimate se;

. *reg positive_sentiment incumbent incumbent_pm l1 l3 l4 l5 l6 l7, cluster(election_id);
. bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm, fe;
(running xtreg on estimation sample)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400

Fixed-effects (within) regression               Number of obs      =       421
Group variable: language                        Number of groups   =         7

R-sq:  within  = 0.1097                         Obs per group: min =        36
       between = 0.0803                                        avg =      60.1
       overall = 0.0390                                        max =       102

                                                Wald chi2(2)       =     61.10
corr(u_i, Xb)  = 0.0370                         Prob > chi2        =    0.0000

                            (Replications based on 70 clusters in election_id)
------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   incumbent |    .356483   .0750253     4.75   0.000     .2094362    .5035298
incumbent_pm |   .2800309   .0749149     3.74   0.000     .1332004    .4268614
       _cons |   1.563074   .1502883    10.40   0.000     1.268515    1.857634
-------------+----------------------------------------------------------------
     sigma_u |    1.34004
     sigma_e |  .68576863
         rho |  .79246181   (fraction of variance due to u_i)
------------------------------------------------------------------------------

. lincom _cons*1;

 ( 1)  _cons = 0

------------------------------------------------------------------------------
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |   1.563074   .1502883    10.40   0.000     1.268515    1.857634
------------------------------------------------------------------------------

. matrix crab[1,1] = r(estimate);

. matrix crab[1,2] = r(se);

. lincom _cons*1 + incumbent*1;

 ( 1)  incumbent + _cons = 0

------------------------------------------------------------------------------
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |   1.919557   .1651512    11.62   0.000     1.595867    2.243248
------------------------------------------------------------------------------

. matrix crab[2,1] = r(estimate);

. matrix crab[2,2] = r(se);

. lincom _cons*1 + incumbent*1 + incumbent_pm*1;

 ( 1)  incumbent + incumbent_pm + _cons = 0

------------------------------------------------------------------------------
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |   2.199588   .1841952    11.94   0.000     1.838572    2.560604
------------------------------------------------------------------------------

. matrix crab[3,1] = r(estimate);

. matrix crab[3,2] = r(se);

. coefplot (matrix(crab[.,1]), se(crab[.,2]) offset(0) 
>         lwidth(thick) m(smcircle) mfcolor("126 163 204") mlc("126 163 204") 
>         ciop(lcolor("126 163 204"))), legend(off) 
>         xtitle("") ytitle("Positive Sentiment", size(3)) levels(95)   
>         coeflabels(r1="Opposition Party" r2="Non-PM Incumbent Party" r3="PM Incumbent Party",  tlcolor(black) labcolor(black) labsize(2.5)) 
>         grid(n) yscale(noline) xscale(noline)
>         ylab(1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6, tlcolor(black) labcolor(black) labsize(2.5))  
>         yline(0, lcolor(gray)) vertical scheme(burd);

. graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig3.pdf", replace;
(file C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig3.pdf written in PDF format)

. *     ****************************************************************  *;
. *       Replication complete                                            *;
. *     ****************************************************************  *;
. log close;
      name:  <unnamed>
       log:  C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure3.log
  log type:  text
 closed on:  14 Jan 2019, 15:42:52
------------------------------------------------------------------------------------------------------------------------------------------------
